package com.mairuide.casemanage.controller;

import com.mairuide._frame.base.BaseController;
import com.mairuide.casemanage.pojo.CaseType;
import com.mairuide.casemanage.pojo.PersonType;
import com.mairuide.casemanage.service.PersonTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: zyj
 * @Date: 2019/1/2 09:22
 * @Description:
 */
@Controller
@RequestMapping("/persontype")
public class PersonTypeController extends BaseController {
    @Autowired
    private PersonTypeService personTypeService;

    @RequestMapping("/allpersontype")
    @ResponseBody
    public List<PersonType> getAllPersonType(){
        List<PersonType> allPersonType = personTypeService.getAllPersonType();
        return allPersonType;
    }

    @RequestMapping("/update")
    @ResponseBody
    public Object update(PersonType personType){
        Map<String,String> map = new HashMap<>();
        if (personType.getId()!=null){
            personType.setIsDelect(0);
            personTypeService.save(personType);
            map.put("msg","修改成功");
        }else {
            map.put("msg","修改失败");
        }
        return map;
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save(PersonType personType){
        PersonType type = personTypeService.getisExist(personType.getPersonType());
        Map<String,String> map = new HashMap<>();
        if (type!=null){//存在就修改删除状态
            type.setIsDelect(0);
            personTypeService.save(type);
        }else {
            personTypeService.save(personType);
        }
        return map.put("msg","添加成功");
    }

    @RequestMapping("/delect")
    @ResponseBody
    public Object delect(Integer id){
        Map<String,String>map = new HashMap<>();
        if (id!=null){//存在就修改删除状态
            PersonType one = personTypeService.findOne(id);
            one.setIsDelect(1);
            personTypeService.save(one);
            return map.put("msg","删除成功");
        }else {
            return map.put("msg","删除失败");
        }

    }

}
